﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "AddPlatformPages.h"
#include "GbmpUiPlatformCommandIds.h"
#include "StructureRibbonControlIds.h"
#include "GcmpCommandState.h"
#include "IPublishConfig.h"

#include "IRibbon.h"
#include "IRibbonPage.h"
#include "IRibbonGroup.h"
#include "IMainWindow.h"
#include "ICommandButtonDefinition.h"
#include "ICommandButtonMenuDefinition.h"
#include "ICommandMenuItemDefinition.h"
#include "IPageHandler.h"
#include "GcmpModel.h"
#include "ICheckBoxGroupDefinition.h"
#include "ICheckBoxGroupHandler.h"
#include "ICheckBoxGroupEventArgs.h"

#include "IDocument.h"
#include "UiDocumentViewUtils.h"
#include "IUserTransaction.h"

#include "ISelection.h"
#include "IPureGraphicsElement.h"
#include "IGraphicsNodeReference.h"
#include "IElementModelShape.h"
#include "IGraphicsElementShape.h"
#include "IGraphicsText.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;

EXPOSE_DEBUG_MODE_EXPORT(ShowTwoDimensionalDrawing,GCMP_MODEL_EXPORT);

namespace
{
    class gbmpPaperPageHandler : public IPageHandler
    {
    public:
        gbmpPaperPageHandler() {}
        virtual ~gbmpPaperPageHandler() {}

    public:

        virtual bool IsVisible() const override
        {
            if ((DEBUG_MODE(ShowTwoDimensionalDrawing)))
            {
                return GcmpCommandState::IsInProjectEnvironment() && !GcmpCommandState::IsInAnimationEnvironment();
            }
            else
                return false;
        }
        virtual bool IsEnabled() const override
        {
            return true;
        }
    };
}

void AddPlatformPages::AddPagePaper()
{
    //默认开启DebugMode。
    gcmp::DebugModeManager::Singleton().SetDebugMode(L"ShowTwoDimensionalDrawing", true);

    OwnerPtr<IRibbonPage> opPage = IRibbonPage::Create(ID_PAGE_GBMP_PAPER, GBMP_TR(L"图纸"));
    DBG_WARN_AND_RETURN_VOID_UNLESS(opPage, L"opPage为空",L"GDMPLab",L"2024-03-30");
    opPage->SetPageHandler(TransferOwnership(NEW_AS_OWNER_PTR(gbmpPaperPageHandler)));

    //图纸界面
    {
        const std::wstring groupId(L"gbmpPaperGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"创建"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_CREATE_PAPER, GBMP_TR(L"创建图纸"), GBMP_TR(L"创建图纸"), ID_CMD_CREATE_PAPER, L":/images/view/平面视图.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_CREATE_VIEW_PORT, GBMP_TR(L"创建视口"), GBMP_TR(L"创建视口"), ID_CMD_CREATE_VIEW_PORT, L":/images/view/剖面视图.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        opPage->AddGroup(TransferOwnership(opGroup));
    }

    IRibbon* pRibbon = IMainWindow::GetMainWindow()->GetRibbon();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pRibbon, L"pRibbon为空",L"GDMPLab",L"2024-03-30");

    pRibbon->AddPage(TransferOwnership(opPage));
}
